package com.youdianstar.app.ui

import androidx.lifecycle.viewModelScope
import com.youdianstar.app.support.ApiRepository
import com.youdianstar.app.common.base.BaseViewModel
import com.youdianstar.app.common.event.NetStateLiveData
import com.youdianstar.app.entity.TouchIDSys
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch


/**
 * File: SettingViewModel
 * Author: 82149 Create: 2021/10/26 12:20
 * Changes (from 2021/10/26)
 * --------------------------------------------------
 * description: 设置页面
 * ---------------------------------------------------
 *
 */
class SettingViewModel(private val repo: ApiRepository) : BaseViewModel(){

    val logoutLiveData = NetStateLiveData<Any>()

    fun logout(){
        viewModelScope.launch (Dispatchers.IO){
            repo.userLogout(logoutLiveData)
        }
    }

    val switchLiveData = NetStateLiveData<Any>()

    /**
     * Switch language
     * @param abb 语言切换,可用值:ZH,EN,FR,IT,DE
     */
    fun languageSwitch(abb:String){
        showLoading()
        viewModelScope.launch (Dispatchers.IO){
            repo.languageSwitch(abb,switchLiveData)
        }
    }

    val touchIdResultLiveData = NetStateLiveData<Any>()

    /**
     * 账号 -生物识别信息更新
     *
     * @param request 账户token数据
     */
    fun accountTouchIdSys(request: TouchIDSys) {
        showLoading()
        viewModelScope.launch(Dispatchers.IO) {
            repo.accountTouchIdSys(request, touchIdResultLiveData)
        }
    }

}